<template>
	<view class="addEditForm">
		<view class="data-form bgfff">
			<view class="data-form-item flex-ac">
				<text class="data-form-label f30">区域名称</text>
				<view class="data-form-input">
					<input type="text" :disabled="optionDisabled" v-model="dataForm.keywords"
						:placeholder="optionDisabled?'-':'请输入关键词'" placeholder-class="plStyle" />
				</view>
			</view>
			<view class="data-form-item flex-ac" v-if="!optionDisabled">
				<text class="data-form-label f30">区域图片（多张）</text>
				<view class="data-form-input">
					<gui-upload-images2 @change="choosePhoto" fileName="file" ref="uploadimgcom" @uploaded="uploaded"
						:uploadServerUrl="`${$http.config.baseUrl}/api/common/upload`"
						:maxFileNumber="3"></gui-upload-images2>
				</view>
			</view>
			<view class="data-form-item flex-ac" v-else>
				<text class="data-form-label f30">区域图片（多张）</text>
				<view class="data-form-input">
					<view class="img-module flex-ac-wrap flex1">
						<image class="img-module-item" v-for="(img,imgIdx) in 4" :key="imgIdx"
							@tap="previewImg('/static/logo.png,/static/logo.png,/static/logo.png',imgIdx)"
							src="/static/logo.png" mode="aspectFill"></image>
					</view>
				</view>
			</view>
		</view>
		<view class="right-area-footer2 flex-ac bgfff" v-if="!optionDisabled">
			<view class="saveBtn cancleBtn" @tap="handleCancle">取消</view>
			<view class="saveBtn" @tap="handleSubmit">保存</view>
		</view>
	</view>
</template>

<script>
	import xiaEditor from '@/components/xia-editor/xia-editor.vue'
	export default {
		components: {
			xiaEditor
		},
		data() {
			return {
				did: '',
				dataForm: { //表单
					keywords: '',
					selectVal: '111',
					dateVal: '',
					// dateRangeVal:''
					startTime: '',
					endTime: '',
					imgUrl: '',
				},
				cpddDateRangeVal: '',
				cpddDateRangeVal2: '',
				selectList: [], //上一页带过来，如果上一页用不到，可以在这里调用赋值
				optionDisabled: false,
				needPploadedImgs: [], //选择图片列表
			}
		},
		onLoad(options) {
			console.log('options', options);
			this.did = options.id || ''
			this.optionDisabled = options.op == 'look' ? true : false
			let title = options.op == 'look' ? '详情' : options.op == 'add' ? '新增' : '编辑'
			uni.setNavigationBarTitle({
				title
			})
		},
		methods: {
			handleCancle() {
				this.$u.back()
			},
			handleSubmit() {
				console.log('提交');
				uni.$emit('reFlashList')
				this.$u.msg('已新增')
				this.$u.back(1, 1000)
				if (!this.formData.content) {
					this.$u.msg('请填写评论内容！')
					return;
				}
				// this.formData.orderNo = this.dataObj.orderNo
				uni.showLoading({
					mask: true,
					title: '正在上传...'
				})
				if (this.needPploadedImgs.length < 1) {
					this.addData()
				} else {
					this.$refs.uploadimgcom.upload();
				}
			},
			previewImg(img, idx) {
				let urls = img.split(',')
				uni.previewImage({
					urls,
					current: idx
				})
			},
			choosePhoto(e) { //选择图片
				this.needPploadedImgs = e;
			}, // 图片上传完毕执行 uploaded 函数
			uploaded: function(uploadedImgs) {
				console.log('图片上传完毕，开始提交数据');
				// 组合数据给后端 api 提交
				console.log(uploadedImgs);
				let arr = []
				for (var i = 0; i < uploadedImgs.length; i++) {
					arr.push(uploadedImgs[i].url)
				}
				console.log(arr);
				console.log('全部数据 :');
				this.formData.image = arr.join()
				this.addData()
				// 至此数据以及收集完毕
			},

		}
	}
</script>

<style>

</style>